@extends('layouts.app')

@section('content')
    <h3 class="page-title">@lang('global.manage.permissions.title')</h3>
    
    {!! Form::model($permission, ['method' => 'PUT', 'route' => ['admin.manage.permissions.update', $permission->id]]) !!}

    <div class="panel panel-default">
        <div class="panel-heading">
            @lang('global.app_edit')
        </div>

        <div class="panel-body">
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('name',trans("global.manage.permissions.fields.name").'*', ['class' => 'control-label']) !!}
                    {!! Form::text('name', old('name'), ['class' => 'form-control', 'placeholder' => '', 'required' => '']) !!}
                    <p class="help-block"></p>
                    @if($errors->has('name'))
                        <p class="help-block">
                            {{ $errors->first('name') }}
                        </p>
                    @endif
                </div>
            </div>

            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('explain', trans("global.manage.permissions.fields.explain").'*', ['class' => 'control-label']) !!}
                    <!-- {!! Form::text('explain', old('explain'), ['class' => 'form-control', 'placeholder' => '', 'required' => '']) !!} -->
                    @if(!empty($permission->hasDetails))
                    <input class="form-control" placeholder="" required="" name="explain" type="text" id="explain" value="{{$permission->hasDetails->explain}}">
                    @else
                    <input class="form-control" placeholder="" required="" name="explain" type="text" id="explain" value="">
                    @endif
                    <p class="help-block"></p>
                    @if($errors->has('explain'))
                        <p class="help-block">
                            {{ $errors->first('explain') }}
                        </p>
                    @endif
                </div>


            </div>
            
            <div class="row">
                <div class="col-xs-12 form-group">
                    {!! Form::label('classify', trans("global.manage.permissions.fields.classify").'*', ['class' => 'control-label']) !!}
                    <!-- 
                        {!! Form::select('classify[]', $classify, old('classify') ? old('classify') : '', ['class' => 'form-control select2', 'multiple' => 'multiple']) !!}
 -->

                        <select class="form-control select2"  data-placeholder="请选择权限分类" style="width: 100%;" name="classify">
                            <option value="" >请选择权限分类</option> 
                            @foreach($classify as $cl_k => $cla)
                            <optgroup label="{{$cla['title']}}">
                                @foreach($cla->classifyHasMany as $clss_k => $class) 
                                    @if(!empty(count($permission->classify_belongsToMany)) && $permission->classify_belongsToMany[0]->id==$class['id'])
                                        <option value="{{$class['id']}}" selected >{{$class['title']}}</option>
                                    @else
                                        <option value="{{$class['id']}}">{{$class['title']}}</option>
                                    @endif

                                @endforeach
                            </optgroup>
                            @endforeach
                        </select>


                    <p class="help-block"></p>
                    @if($errors->has('classify'))
                        <p class="help-block">
                            {{ $errors->first('classify') }}
                        </p>
                    @endif
                </div>
            </div>

        </div>
    </div>

    {!! Form::submit(trans('global.app_update'), ['class' => 'btn btn-danger']) !!}
    {!! Form::close() !!}
@stop

